package com.tbm.console.proj.controller;

import com.alibaba.fastjson.JSONArray;
import com.tbm.console.base.controller.BaseController;
import com.tbm.console.common.constant.ConsoleConstant;
import com.tbm.console.proj.entity.LocalUserInfoEntity;
import com.tbm.console.proj.entity.SystemUser;
import com.tbm.console.proj.service.LocalUserInfoService;
import com.tbm.console.util.JsonUtils;
import com.tbm.console.util.JurisdictionUtil;
import com.tbm.console.util.PageData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

//说明 字符串：ChartShowInfo，作为替换字符串

@Controller
public class ChartShowInfoController extends BaseController {

    @Autowired
    private LocalUserInfoService localUserInfoService;

    /**
     * 人员关系图
     * @return
     */
    @RequestMapping("/chartShowInfo-list")
    public ModelAndView listManage(){
        ModelAndView modelAndView = this.getModelAndView();
        String viewName = "login";
        if(JurisdictionUtil.isValid()){
            viewName = "chartShowInfo/chartShowInfo-list";
        }
        modelAndView.setViewName(viewName);
        return modelAndView;
    }

    @RequestMapping("/chartBandnfo-list")
    public ModelAndView chartBandnfoList(){
        ModelAndView modelAndView = this.getModelAndView();
        String viewName = "login";
        if(JurisdictionUtil.isValid()){
            SystemUser systemUser = JsonUtils.jsonToObject(this.getRequest().getSession().getAttribute(ConsoleConstant.SESSIONUSER).toString(), SystemUser.class);
            PageData pageData = new PageData();
            pageData.put("userId", systemUser.getId());
            List<LocalUserInfoEntity> all = localUserInfoService.findAll(pageData);
            if(all.size()==1){
                String password = all.get(0).getPassword();
                List<String> strings = new ArrayList<>();
                List<PageData> result = new ArrayList<>();
                if(null==password||"".equals(password)){
                }else{
                    strings = Arrays.asList(password.split("&"));
                    for(int i=0;i<strings.size();i++){
                        PageData pd = new PageData();
                        pd.put("id", strings.get(i));
                        result.add(pd);
                    }
                }
                modelAndView.addObject("result", result);
            }else{
            }
        }
        viewName = "chartShowInfo/chartBandnfo-list";
        modelAndView.setViewName(viewName);
        return modelAndView;
    }

}